﻿using Microsoft.AspNetCore.Mvc.Controllers;
using System.Reflection;

namespace Fast.DynamicApiController
{
    /// <summary>
    /// 发现动态Api Controller类
    /// </summary>
    public class DynamicApiControllerFeatureProvider : ControllerFeatureProvider
    {
        protected override bool IsController(TypeInfo typeInfo)
        {
            var type = typeInfo.AsType();

            if (!typeof(IDynamicApiController).IsAssignableFrom(type) && type.GetCustomAttribute<DynamicApiControllerAttribute>() == null)
            {
                return false;
            }

            if (!typeInfo.IsPublic || typeInfo.IsAbstract || typeInfo.IsGenericType)
            {
                return false;
            }

            return true;
        }
    }
}
